﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Billing.Dtos;

namespace Billing.Windows
{
    /// <summary>
    /// Interaction logic for StockSearch.xaml
    /// </summary>
    public partial class StockSearch : Window
    {

        public string code = string.Empty;
        public string desc = string.Empty;
        public string stock = string.Empty;

        public StockSearch()
        {
            InitializeComponent();
            txtItemDescription.Focus();
        }

        private void txtItemDescription_TextChanged(object sender, TextChangedEventArgs e)
        {
            
        }

        List<BillingGridItemDto> SearchResult()
        {
            //TODO: Need to find a way to get stcok items from all the braches for MainMenu
            List<Dtos.BillingGridItemDto> items = Utilities.CacheManager.BillingItems;
            List<Dtos.BillingGridItemDto> results = new List<Dtos.BillingGridItemDto>();
            //string pattern = txtItemDescription.Text.Trim();

            if (items.Exists(i => i.Code.ToString() == txtItemDescription.Text.Trim()))
            {
                return items.FindAll(i => i.Code.ToString() == txtItemDescription.Text.Trim());
            }
            else
            {
                return items;
            }
            //foreach (BillingGridItemDto item in items)
            //    if (System.Text.RegularExpressions.Regex.IsMatch(item.Name.Trim(), pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            //        results.Add(item);

            //return results;
            //return null;
        }    

        private void txtItemDescription_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                
                
            }
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.Close();
            }
        }
    }
}
